package com.itdianzi.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itdianzi.service.system.DeptService;
import com.itdianzi.domain.system.Dept;
import com.itdianzi.dao.system.DeptDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptDao deptDao;
    @Override
    public PageInfo findAll(Integer page, Integer size,String companyId) {
        //        调用分页插件的方法，自动帮助我们分页
        PageHelper.startPage(page, size);
        //紧跟在这个方法后的第一个MyBatis查询方法会被进行分页，查询所有即可
        List<Dept> deptList =deptDao.findAll(companyId);

        /*System.out.println(deptList);*/
        //返回分页的数据
        PageInfo pageInfo = new PageInfo(deptList);
        return pageInfo;
    }

    @Override
    public List<Dept> findAll(String companyId) {
        List<Dept> deptList =deptDao.findAll(companyId);
        return deptList;
    }

    @Override
    public void edit(Dept dept) {
        /*System.out.println(123123);*/
        /*获取随机ID*/
        dept.setId(UUID.randomUUID().toString());
        deptDao.save(dept);

    }

    @Override
    public Dept findById(String id) {
        Dept dept = deptDao.findById(id);
        return dept;
    }

    @Override
    public void update(Dept dept) {
        deptDao.update(dept);
    }

    @Override
    public void delete(String id) {
        deptDao.delete(id);
    }



}
